class Foo {
  init() {
    console.log("------- project init --------");
    // this.test(this.fn1, this.fn2, this.fn3)(3);
  }

  // 下面开始测试
  test() {
    // 1. 遍历整个参数对象
    for (var _len = arguments.length, i = _len, arguList = []; i > 0; i--) {
      arguList.push(arguments[i - 1]);
    }
    return function() {
      // // 2. 分离参数跟方法
      // let last = arguList[0];
      // let argList = arguList.slice(1);
      // // 3. 执行传入的方法
      // let res = last;
      // argList.map(item => {
      //   res = item(res);
      // });

      // _2 . 执行传入的方法及参数
      let last = arguList[arguList.length - 1];
      let other = arguList.slice(0, -1);
      return other.reduceRight(function(compose, f) {
        return f(compose);
      }, last.apply(undefined, arguments));
    };
  }

  fn1(params) {
    console.log("这里是fn1，传入参数:", params, ",上下文：", this);
    return "fn1 " + params;
  }
  fn2(params) {
    console.log("这里是fn2，传入参数:", params, ",上下文：", this);
    return "fn2 " + params;
  }
  fn3(params) {
    console.log("这里是fn3，传入参数:", params, ",上下文：", this);
    return "fn3 " + params;
  }
}
export default Foo;
